package com.example.components;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.yzc35326.components.fragment.RadioGroupFragment;

import java.util.ArrayList;
import java.util.zip.Inflater;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

	private static final String TAG = "MainActivity";
	private Button btnCheckBox;
	private ViewPager viewPager;
	private ArrayList<View> fragments = new ArrayList<>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		//加载主界面 ， 是一个ListView
		setContentView(R.layout.activity_main);

		initView();


		Resources resources = getResources();
	}

	private void initView() {
		View view1 = LayoutInflater.from(this).inflate(android.R.layout.simple_list_item_1, null);
		view1.setBackgroundColor(Color.BLACK);
		View view2 = LayoutInflater.from(this).inflate(android.R.layout.simple_list_item_1, null);
		view2.setBackgroundColor(Color.RED);
		View view3 = LayoutInflater.from(this).inflate(android.R.layout.simple_list_item_1, null);
		view3.setBackgroundColor(Color.GREEN);
		View view4 = LayoutInflater.from(this).inflate(android.R.layout.simple_list_item_1, null);
		view4.setBackgroundColor(Color.YELLOW);
		fragments.add(view1);
		fragments.add(view2);
		fragments.add(view3);
		fragments.add(view4);
		viewPager = findViewById(R.id.view_pager_main);
		viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			@Override
			public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
				Log.e(TAG, "onPageScrolled: position=" + position);
				Log.e(TAG, "onPageScrolled: offset=" + positionOffset);
				Log.e(TAG, "onPageScrolled: offsetPx=" + positionOffsetPixels);
			}

			@Override
			public void onPageSelected(int position) {
				Log.e(TAG, "onPageSelected: " + position);
			}

			@Override
			public void onPageScrollStateChanged(int state) {
				switch (state) {
					case ViewPager.SCROLL_STATE_DRAGGING:
						Log.e(TAG, "onPageScrollStateChanged: 正在被拖动");
						break;
					case ViewPager.SCROLL_STATE_IDLE:
						Log.e(TAG, "onPageScrollStateChanged: 静下来了");
						break;
					case ViewPager.SCROLL_STATE_SETTLING:
						Log.e(TAG, "onPageScrollStateChanged: 正在动");
						break;
				}
			}
		});
		viewPager.setAdapter(new MyPagerAdapter(this.fragments));
		this.btnCheckBox = findViewById(R.id.btn_main_checkbox);
		this.btnCheckBox.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.btn_main_checkbox: {
				startActivity(new Intent(this, CheckBoxTest.class));
				break;
			}

			default:
				break;
		}
	}
}